//
//  HttpsManager.m
//  EJLX
//
//  Created by adc on 15/11/9.
//  Copyright © 2015年 江苏一键联信息科技有限公司. All rights reserved.
//

#import "HttpsManager.h"
#import "ASIFormDataRequest.h"
#import "WoDeWeiDian.h"
#import "woDeDingDan.h"
#import "weiXinDingDan.h"
#import "GoodsDetailInfo.h"
#import "GeRenJiShi.h"
#import "GouWuChe.h"
#import "PingJia.h"
#import "SouSuoJieGuoYe.h"
#import "ShangPinXiangQing.h"
#import "ShangPinFeNLeiShuXing.h"
#import "HuoQuDianPuSheZhi.h"
#import "WeiDianLeiJiShouRu.h"
#import "QueRenDingDan.h"
#import "ZhiDeSou.h"
@implementation HttpsManager

#pragma mark - Pre.im
+(void)priBlock:(void(^)(NSDictionary *dict))block{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"http://pre.im/api/v1/app/update"]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    
    [request setPostValue:@"3c1be8cea4050cb495c43fde727f5bfc" forKey:@"app_key"];

    [request setPostValue:@"b8b9912d03adff4c5cf3bd9fe84298af" forKey:@"user_key"];

    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
    
    block(dict);
    [request startAsynchronous];
}



+(void)removeShouCangWithType:(NSString *)type favorited:(NSString *)fav completionBlock:(void(^)(NSString *errmsg))block{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/favorite_del",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:type forKey:@"type"];
    [request setPostValue:fav forKey:@"favoriteId"];
    [request setCompletionBlock:^{
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        block(dict[@"errmsg"]);
    }];
    [request startAsynchronous];
    
}

+(void)addGoodsFofCarWithProductID:(NSString *)productID Completion:(void(^)(addInfoGoodToCar*info))completion
{
    
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/product/class_attr_list",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:productID forKey:@"productId"];
    
    request.completionBlock=^
    {
        NSLog(@"dict %@",request.responseString);
      
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        
        int errcode = [jsonDic[@"errcode"]intValue];
        if (errcode ==10100||errcode == 10014) {
            completion(nil);
        }else{
              addInfoGoodToCar *goodInfo = [addInfoGoodToCar praseWithDict:jsonDic];
            completion(goodInfo);
        }
       
    };
    [request startAsynchronous];
    
}
+(void)lunboID:(int )ID class:(int )class Block:(void(^)(NSMutableArray *imgArr,NSMutableArray *Class))block{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/comm/advertisement_list",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
   
    NSMutableDictionary *dict =[[NSMutableDictionary alloc] init];
     [dict setObject:[NSNumber numberWithInt:ID] forKey:@"positionId"];
   
    if (class) {
        [dict setObject:[NSNumber numberWithInt:class] forKey:@"categoryId"];
    }
    NSMutableArray *arr = [NSMutableArray arrayWithObject:dict];
     NSString *str =[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    [request setPostValue:str forKey:@"condition"];
       NSMutableArray *imgArray = [NSMutableArray array];
    
    NSMutableArray *typeArray = [NSMutableArray array];
    [request setCompletionBlock:^{
      

        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        
        int errcode = [dict[@"errcode"]intValue];
        if (errcode ==10100 || errcode == 10014) {
            block(nil,nil);
        }else {
            NSArray *data =dict[@"data"][0];
            for (NSDictionary *D in data) {
                NSString *imgUrl = D[@"picture"];
                [imgArray addObject:imgUrl];
                NSString *type =  [NSString stringWithFormat:@"%d", [D[@"type"] intValue]  ];
                [typeArray addObject:type];
            }
            block(imgArray,typeArray);
        
        }
    }];

          request.timeOutSeconds = 60;
           [request startAsynchronous];
    
}





+(BOOL)isLogin{
    //    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    ////    NSString *token = [ud objectForKey:@"token"];
    ////    NSLog(@"token %@",token);
    ////    // token的过期时间
    //   NSDate *date = [ud objectForKey:@"date"];
    
    NSString * accessToken = [[NSUserDefaults standardUserDefaults]objectForKey:@"token"];
   // NSDate * time = [[NSUserDefaults standardUserDefaults]objectForKey:@"time"];
    //NSDate * now = [NSDate date];
   //
    //NSComparisonResult result = [time compare:now];
    
    if (accessToken==NULL ||accessToken==nil||[accessToken isEqualToString:@""])
    {
        return NO;
    }
    return YES ;
}


//    ACCESS_TOKEN;
//    if (ACCESS_TOKEN == NULL || [ACCESS_TOKEN isEqualToString:@""]||ACCESS_TOKEN == nil)
//    {
//        return NO;
//    }
//    NSDate *currentDate = [NSDate date];
//    if ([[currentDate laterDate:date] isEqualToDate:currentDate])
//    {
//        return NO;
//    }
//
//return YES;
//自动登录
+(void)requestZiDongDengLuCompletion:(void(^)(int errcode,NSString*errmsg))complete
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/login_auto",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    request.completionBlock=^
    {
        NSLog(@"++++%@",request.responseString);
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
        
      
        NSString*errmsg=jsonDic[@"errmsg"];
        
        NSDictionary*dataDic=jsonDic[@"data"];
        
        //NSString*str=[NSString stringWithFormat:@"%d",errcode];
        if (errcode==0)
        {
            NSString*token=dataDic[@"token"];
            [self saveToken:token];
            if (complete)
            {
                
                complete(errcode,errmsg);
            }
            
        }
        
        else
        {
            if (complete)
            {
                
                complete(errcode,errmsg);
            }

        }

        
       
    };
    [request startAsynchronous];
    
}
//注册
+(void)registerRequestWithPhoneNumber:(ZhuCeDL*)zhuCe completion:(void(^)(int errcode,NSString*errmsg))completion
{
   
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/register",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:zhuCe.password forKey:@"password"];
    [request setPostValue:zhuCe.phone forKey:@"phone"];
    [request setPostValue:zhuCe.yanZhengMa forKey:@"captcha"];
    [request setPostValue:zhuCe.inviter forKey:@"inviter"];
    request.completionBlock=^
    {
        NSLog(@"77777%@",request.responseString);
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        //NSString*errcode=jsonDic[@"errcode"];
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        NSDictionary*dataDic=jsonDic[@"data"];
        //NSString*token=dataDic[@"token"];
        //NSDictionary*dataDic=jsonDic[@"data"];
        
        NSString*str=[NSString stringWithFormat:@"%d",errcode];
        if ([str isEqualToString:@"0"] )
        {
            NSString*token=dataDic[@"token"];
            [self saveToken:token];
            NSLog(@"---%d%@ \n token %@",errcode,errmsg,token);
        }
        if (completion)
        {
            completion(errcode,errmsg);
        }
        
        
        
        
    };
    [request startAsynchronous];
    
    
}
//登录
+(void)LoginRequestWithPhoneNumber:(ZhuCeDL *)dengLu completion:(void(^)(int errcode,NSString*errmsg))completion
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/login",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:dengLu.phone forKey:@"phone"];
    [request setPostValue:dengLu.password forKey:@"password"];
    request.completionBlock=^
    {
        NSLog(@"%@",request.responseString);
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        
        NSDictionary*dataDic=jsonDic[@"data"];
        
        NSString*str=[NSString stringWithFormat:@"%d",errcode];
        if ([str isEqualToString:@"0"] )
        {
            NSString*token=dataDic[@"token"];
            [self saveToken:token];
            NSLog(@"---%d%@ \n token %@",errcode,errmsg,token);
        }
        
        
        
        if (completion)
        {
            
            completion(errcode,errmsg);
        }
    };
    [request startAsynchronous];
    
}
//信息简介
+(void)requestJianJieXinXiCompletion:(void(^)(XinXiJianJie*xinXi))completion
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/bref_info",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    request.completionBlock=^
    {
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014 ||errcode == 10100)
        {
            if (completion) {
                completion(nil);
            }
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            
            XinXiJianJie*xinXi=[XinXiJianJie userWithDictionary:dataDic];
            
            if (completion)
            {
                completion(xinXi);
                
            }

        }
        
        
        
    };
    [request startAsynchronous];
    
    
}
+(void)saveToken:(NSString*)token
{
    //int time= 1;
   // NSDate*date=[NSDate dateWithTimeIntervalSinceNow:time];
    [[NSUserDefaults standardUserDefaults]setObject:token forKey:@"token"];
    //[[NSUserDefaults standardUserDefaults]setObject:date forKey:@"time"];
    //同步
    [[NSUserDefaults standardUserDefaults]synchronize];
    //
    //    NSUserDefaults*tokenUser=[NSUserDefaults standardUserDefaults];
    //    [tokenUser setObject:token forKey:@"token"];
    //    [tokenUser synchronize];
    
    
    
}
//修改密码
+(void)requestXiuGaiMiMaXiuGai:(XiuGaiMiMa*)xiuGai compeletion:(void(^)(int errcode,NSString*errmsg,NSString*token))compeletion
{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/pswd_mod",HTTPS_ID]]];
    [request setPostValue:xiuGai.password forKey:@"password"];
    [request setPostValue:xiuGai.phone forKey:@"phone"];
    [request setPostValue:xiuGai.captcha forKey:@"captcha"];
    request.completionBlock=^
    {
        
        NSLog(@"mima %@",request.responseString);
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        
        
        NSString*errmsg=jsonDic[@"errmsg"];
       // NSDictionary*dataDic=jsonDic[@"data"];
     //   NSString*token=dataDic[@"token"];
        //NSString*token=jsonDic[@"token"];
        if (compeletion)
        {
          
            compeletion(errcode,errmsg,nil);
        }
        
        
        
    };
    [request startAsynchronous];
}
+(void)shouCangJiaType:(NSString *)type page:(NSString *)page completionBlock:(void(^)(NSMutableArray *array))block{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/favorite_list",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:type forKey:@"type"];
    [request setPostValue:page forKey:@"page"];
    [request setCompletionBlock:^{
        NSLog(@"type %@////111111/////%@",type,request.responseString);
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        int errcode = [dict[@"errcode"] intValue];
        if (errcode ==10100||errcode ==10014) {
            block(nil);
        }else{
            NSMutableArray *array = [NSMutableArray array];
            NSArray *productFavorites = dict[@"data"][@"productFavorites"];
            for (NSDictionary *dict in productFavorites) {
                ShouCangJia *shoucang = [ShouCangJia parseShouCangJiaWithDictionary:dict];
                [array addObject:shoucang];
            }
            block(array);
        }
    }];
    [request startAsynchronous];
    
    
}

#pragma mark - 首页轮播图片
+(void)imageRequestBlock:(void(^)(NSArray *imgArr,NSArray *typeArr))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/home/ads.do",HTTPS_ID]]];
                                            request.delegate = self;
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:@"123" forKey:@"userId"];

    [request setCompletionBlock:^{
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
      
          int errcode = [dict[@"errcode"]intValue];
        if (errcode ==10100 || errcode == 10014) {
            block(nil,nil);
        }else {
            NSArray *imageArray = [dict objectForKey:@"data"];
            
            NSMutableArray *newArray = [NSMutableArray new];
            NSMutableArray *typeArr = [NSMutableArray new];
            for (NSDictionary *newDict in imageArray) {
                NSString *imageURL = [newDict objectForKey:@"imgUrl"];
                NSString *type = [newDict objectForKey:@"type"];
                [newArray addObject:imageURL];
                [typeArr addObject:type];
            }
            block(newArray,typeArr);
        }
     
    }];
    [request startAsynchronous];
   
}
#pragma mark - 个人信息
+(void)requestForPersonalBlock:(void(^)(NSDictionary  *dict))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/usercenter/homeInfo.do",HTTPS_ID]]];
  
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:@"123" forKey:@"userId"];
    
    [request setCompletionBlock:^{
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
       
         int errcode = [dict[@"errcode"]intValue];
        BEGAIN_LOGIN_block( NSDictionary *newDict = [dict objectForKey:@"data"];
                            block(newDict););
    
    }];
    [request startAsynchronous];
    
}


#pragma mark - 提交个人资料
+(void)postPeopleInforName:(NSString *)name card:(NSString *)card address:(NSString *)address email:(NSString *)email shopName:(NSString *)shopName  block:(void(^)(NSString *msg))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/profile_update",HTTPS_ID]]];
    
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:name forKey:@"name"];
    [request addPostValue:card forKey:@"idCard"];
    [request addPostValue:address forKey:@"address"];
    [request addPostValue:email forKey:@"email"];
    [request addPostValue:shopName forKey:@"shopname"];
    
    [request setCompletionBlock:^{
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        NSString *msg = [dict objectForKey:@"errmsg"];
        
        block(msg);
    }];
    
    [request startAsynchronous];
    
}

+(void)postBankCard:(NSString *)card name:(NSString *)name bank:(NSString *)bank location:(NSString *)diqu zhihang:(NSString *)zhihang completionBlock:(void(^)(NSString *msg))block{
    
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@user/bank_update",HTTPS_ID]]];
    
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:card forKey:@"card"];
    [request addPostValue:name forKey:@"name"];
    [request addPostValue:bank forKey:@"bank"];
    [request addPostValue:diqu forKey:@"location"];
    [request addPostValue:zhihang forKey:@"branch"];
    
    [request setCompletionBlock:^{
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        NSString *msg = [dict objectForKey:@"errmsg"];
        
        block(msg);
    }];
    
    [request startAsynchronous];
    
}

+(void)postPersonImagesCompletion:(void(^)(int errcode,NSString*errmsg))complete
{
    NSArray *array = [[NSArray alloc] initWithObjects:@"idfront",@"idBack",@"cardBack",@"cardFront",@"idFace",@"creditCardFront", nil];
    
    
    
    for (int i = 0; i <6; i++) {
        // NSArray *arr =@[@"idfront",@"idBack",@"cardBack",@"cardFront",@"idFace",@"creditCardFront"];
        
        NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/img%d.jpg",i ]] ;
        //stringByAppendingPathComponent:[NSString stringWithFormat:@"img%d.jpg",i ]]  ;
        NSString *imageName = [NSString stringWithFormat:@"img%@.jpg",array[i]];
        UIImage *savedImage = [UIImage imageWithContentsOfFile:imagePath];
        NSData *imgData = UIImageJPEGRepresentation(savedImage, 1.0);
        
        //                NSArray *a = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        //                NSString *filepath = [a objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"img%d.jpg",i ];
        //                UIImage *image = [UIImage imageWithContentsOfFile:filepath];
        NSURL*url=[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/pics_update",HTTPS_ID]];
        __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:url];
        
        [request addPostValue:ACCESS_TOKEN forKey:@"token"];
        [request setPostValue:@"" forKey:array[i]];
        
        switch (i ) {
            case 0:
                [request addData:imgData withFileName:imageName andContentType:@"image/jpeg" forKey:@"idfront"];
                break;
            case 1:
                [request addData:imgData withFileName:imageName andContentType:@"image/jpeg" forKey:@"idBack"];
                break;
            case 2:
                [request addData:imgData withFileName:imageName andContentType:@"image/jpeg" forKey:@"cardBack"];
                break;
            case 3:
                [request addData:imgData withFileName:imageName andContentType:@"image/jpeg" forKey:@"cardFront"];
                break;
            case 4:
                [request addData:imgData withFileName:imageName andContentType:@"image/jpeg" forKey:@"idFace"];
                break;
            case 5:
                [request addData:imgData withFileName:imageName andContentType:@"image/jpeg" forKey:@"creditCardFront"];
                break;
                
            default:
                break;
        }
        [request appendPostData:imgData];
    
           request.completionBlock=^
        {
            __strong typeof(request) strongRequest = request;
            NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:strongRequest.responseData options:NSJSONReadingMutableContainers error:nil];
            int errcode=[jsonDic[@"errcode"]intValue];
            NSString*errmsg=jsonDic[@"errmsg"];
            NSLog(@"img %@",request.responseString);
            if (complete)
            {
                complete(errcode,errmsg);
            }
            
            
        };
        
        [request startAsynchronous];
        
        
    }
    
    
    
}
#pragma mark - 收货地址
+(void)postAdressName:(NSString *)name phone:(NSString *)phone address:(City *)address  completionBlock:(void(^)(NSString *msg))block{
    
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/delivery_address_new",HTTPS_ID]]];
    
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:phone forKey:@"phoneNumber"];
    [request addPostValue:name forKey:@"name"];
  
    if (address.country == nil||address.country == NULL) {
        NSString *add = [NSString stringWithFormat:@"%@,%@,%@",address.province,address.city,address.details];
         [request addPostValue:add forKey:@"address"];
    }else{
    NSString *add = [NSString stringWithFormat:@"%@,%@,%@,%@",address.province,address.city,address.country,address.details];
         [request addPostValue:add forKey:@"address"];
    }
   
    
    
    [request setCompletionBlock:^{
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        NSString *msg = [dict objectForKey:@"errmsg"];
        
        block(msg);
    }];
    
    [request startAsynchronous];
    
}
#pragma mark - 获取收获地址
+(void)getAddressBlock:(void (^)(NSMutableArray *addressArray))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/delivery_address_list",HTTPS_ID]]];
    
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];


    [request setCompletionBlock:^{
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        int errcode = [dict[@"errcode"] intValue];
        BEGAIN_LOGIN_block( NSArray  *data =dict[@"data"];
                           NSMutableArray *array = [NSMutableArray array];
                           for (NSDictionary *address in data) {
                               Address *add = [Address praseWithDictionary:address];
                               [array addObject:add];
                           }
                           block(array);
                           );
       
           }];
    
    [request startAsynchronous];
    

    
}

#pragma mark - 获取商品类



+(void)classOfGoodswithCategoryID:(int)cateId completionBlock:(void(^)(NSMutableArray *arr))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/product/subcategory_list",HTTPS_ID]]];
    
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:[NSNumber numberWithInt:cateId] forKey:@"categoryId"];
    [request setCompletionBlock:^{
        NSDictionary *dict = [ NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        int errcode = [dict[@"errcode"] intValue];
        BEGAIN_LOGIN_block( NSMutableArray *arr = [NSMutableArray array];
                           
                           
                           NSDictionary *data = dict[@"data"];
                           for (NSDictionary *goods in data) {
                               ClassOfGoods *oneGoods = [ClassOfGoods praseWithDictionary:goods];
                               [arr addObject:oneGoods];
                           }
                           block(arr);
                           
                           )
           }];
    [request startAsynchronous];
   
}
+(void)classBtnBlock:(void(^)(NSMutableArray *array))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/product/category_list",HTTPS_ID]]];
    
  
    
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    
    [request setCompletionBlock:^{
        
        NSLog(@"dict %@",request.responseString);
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
                 NSMutableArray *arr = [NSMutableArray array];
                           NSArray *data =dict[@"data"];
        
                           for (NSDictionary *dict in data) {
                               NSString *name = dict[@"categoryName"];
                               [arr addObject:name];
                           }
                           block(arr);
       
    }];
    //request.timeOutSeconds = 60;
    [request startAsynchronous];
}
#pragma mark - 商品列表

#pragma mark - 个人商品详情

#pragma mark - 搜素历史

#pragma mark - 我的微店商品列表
+(void)requestForMyShopDoodsBlock:(void(^)(NSMutableArray *goodsArray))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/delivery_address_list",HTTPS_ID]]];

    request.delegate = self;
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:@"123" forKey:@"userId"];
    
    [request setCompletionBlock:^{
        NSString *str = [[NSString alloc] initWithData:request.responseData encoding:NSUTF8StringEncoding];
      
       NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        
         int errcode = [dict[@"errcode"] intValue];
        BEGAIN_LOGIN_block(
                           NSArray *allGodds = dict[@"data"][@"productList"];
                           
                           NSMutableArray *goodsArray = [NSMutableArray array];
                           for (NSDictionary *oneGoods in allGodds) {
                               GoodsForMyShop *goods = [GoodsForMyShop praseGoodsForMyShopWithDictionary:oneGoods];
                               [goodsArray addObject:goods];
                           }
                           block(goodsArray);)
       
         }];
    [request startAsynchronous];
    
}
#pragma mark -版本更新
+(void)requsetGetVersionForAPPBlock:(void(^)(NSDictionary *dict))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/comm/version_check",HTTPS_ID]]];
    
    request.delegate = self;
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:@"2" forKey:@"apptype"];
    
    [request setCompletionBlock:^{
      
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];

        block(dict);
    }];
    [request startAsynchronous];
  
}
#pragma mark - 系统公告
+(void)requestForPublicWithType:(int)type page:(int)page  completionBlock:(void(^)(NSMutableArray *publicArr,int totalPage ,int currentPage,int pageNum))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/comm/bulletin_list",HTTPS_ID]]];
    
    request.delegate = self;
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:[NSNumber numberWithInt:type] forKey:@"type"];
    [request addPostValue:[NSNumber numberWithInt:page] forKey:@"page"];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];

    [request setCompletionBlock:^{
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
     
  int errcode = [dict[@"errcode"]intValue];
        if (errcode ==10100 || errcode == 10014) {
            block(nil,nil,nil,nil);
        }else {
            NSMutableArray *publicArray = [NSMutableArray array];
            NSDictionary *data = dict[@"data"];
            int totalPage = [data[@"totalPage"] intValue];
            int currentPage = [data[@"page"] intValue];
            int pageNum = [data[@"pageSize"] intValue];
            
            NSArray *listArr = data[@"list"];
            for (NSDictionary *dict in listArr) {
                PublicNotice *notice = [PublicNotice prasePublicNoticeWithDictionary:dict];
                [publicArray addObject:notice];
            }
            block(publicArray,totalPage, currentPage,pageNum);
        }


       
    }];
    [request startAsynchronous];

}
#pragma mark - shopping
//保存店铺设置
+(void)requestSave:(SaveDianPuSheZhi*)save completion:(void(^)(int errcode,NSString*errmsg))complete
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/shop/info_update",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:save.name forKey:@"name"];
    [request setPostValue:save.wechat forKey:@"wechat"];
    [request setPostValue:save.phone forKey:@"phone"];
    [request setPostValue:save.address forKey:@"address"];
    [request setPostValue:save.closeminute forKey:@"closeminute"];
    request.completionBlock=^
    {
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
       
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        
        
        
        
        if (complete)
        {
            
            complete(errcode,errmsg);
        }
    };
    [request startAsynchronous];
    
}

+(void)requestForShoppingViewBlock:(void(^)(ShoppingModel *shopping))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/comm/shopcenter",HTTPS_ID]]];
    
//   [request setAuthenticationScheme:@"https"];
//    [request setValidatesSecureCertificate:NO];
    
    request.timeOutSeconds = 60;
      [request setCompletionBlock:^{

          NSLog(@"zzzzz%@",request.responseString);
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
          int errcode = [dict[@"errcode"] intValue];
          
          if (errcode ==10100||errcode ==10014) {
              block(nil);
          }else{
   ShoppingModel *shop = [ShoppingModel prasePublicNoticeWithDictionary:dict];
                             block(shop);

          }
      }];
    
    [request startAsynchronous];
}
//我的微店首页
//我的微店首页

+(void)requestGetWoDeWeiDianCompletion:(void(^)(FirstWoDeWeiDian*weiDian))Complete

{
   
    NSString*str=[NSString stringWithFormat:@"%@/shop/mine_home",HTTPS_ID];
    //NSURL*url=[NSURL URLWithString:@"http://121.42.211.76/shop/mine_home?page=0&token=31447845156269"];
    NSURL*url=[NSURL URLWithString:str];
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:@"0" forKey:@"page"];
    
    request.completionBlock=^
    {
        NSLog(@"我的微店首页  %@",request.responseString);
       NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];

        

        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (Complete)
            {
                Complete(nil);
            }
                    }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            FirstWoDeWeiDian*weiD=[FirstWoDeWeiDian userWithDictionary:dataDic];
            if (Complete)
            {
                Complete(weiD);
            }

        }
        
       
    };
    [request startAsynchronous];
}
+(void)requestGetWODeShouRu:(void(^)(WoDeShouRu*shouRu))Complete
{  NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/profit/mine",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];

    request.completionBlock=^
    {
              NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            
            if (Complete) {
                Complete(nil);
            }
                    }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            WoDeShouRu*woDe=[WoDeShouRu userWithDictionary:dataDic];
            if (Complete)
            {
                Complete(woDe);
            }

        }
        
    };
    [request startAsynchronous];
}

//我的分店
+(void)requestMyFenDian:(NSString*)status completion:(void(^)(MyFenDian*fD))complete
{
    
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/shop/branch_shops",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:status forKey:@"status"];
    [request setPostValue:@"0" forKey:@"page"];
    
    
    
    request.completionBlock=^
    {
        NSLog(@"zzzz%@",request.responseString);
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (complete)
                
            {
                complete(nil);
            }
        }
        else
        {
            
            NSDictionary*dataDic=jsonDic[@"data"];
            
            MyFenDian*woDe=[MyFenDian userWithDictionary:dataDic];
            if (complete)
            {
                complete(woDe);
            }

        }
        
        
        
    };
    [request startAsynchronous];

    
}
+(void)wanShancomplection:(void(^)(int  genRen,int diZhi,int img))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/user/profile_status",HTTPS_ID]]];
    
    [request setAuthenticationScheme:@"https"];
    [request setValidatesSecureCertificate:NO];
    
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setCompletionBlock:^{
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        int errcode = [dict[@"errcode"]intValue];
        if (errcode ==10100 || errcode == 10014) {
 
        }else {
            NSDictionary *data = [dict objectForKey:@"data"];
            
            int  pro = [data[@"profile"] intValue];
            int bank = [data[@"bank"] intValue];
            int img = [data[@"pics"] intValue];
            
            block(pro,bank,img);
        }


       
    }];
    
    [request startAsynchronous];
    
    
}

//修改头像
+(void)requestToUploadImage:(UIImage*)image completion:(void(^)(int errcode,NSString*errmsg,NSString*image))complete
{
    NSString*str=[NSString stringWithFormat:@"%@/shop/avatar_mod",HTTPS_ID];
    NSURL*url=[NSURL URLWithString:str];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:url];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    NSData*data=UIImageJPEGRepresentation(image, 0.5);
    [request addData:data withFileName:@"testimage.png" andContentType:@"image/png" forKey:@"avatar"];
    //[request addFile:image forKey:@"brand"];
    [request appendPostData:data];
    
    
    request.completionBlock=^
    {
        NSLog(@"aaa%@",request.responseString);
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        //        if ([jsonDic[@"errmsg"]isKindOfClass:[NSNull class]])
        //        {
        //
        //        }
        //        else
        //        {
        //
        //        }
        // NSString*image=jsonDic[@"data"];
        if (errcode==0)
        {
            //NSString*image=dataDic[@"avatar"];
            
            if (complete)
            {
                complete(errcode,errmsg,nil);
            }
            
        }
        else
        {
            if (complete)
            {
                
                complete(errcode,errmsg,nil);
            }
        }
        
        
    };
    [request startAsynchronous];}


#pragma mark - detail for goods (shopping)购物中心
+(void)requestForDetailInfoWithProductID:(int)ID completionBlock:(void(^) (GoodsDetailInfo *detail))block{
    
    
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/product/info",HTTPS_ID]]];
    [request addPostValue:[NSNumber numberWithInt:ID] forKey:@"productId"];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setCompletionBlock:^{
        NSLog(@"res %@",request.responseString);
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
         int errcode = [dict[@"errcode"] intValue];
        if (errcode ==10100||errcode == 10014) {
            block(nil);
        }else {
            NSDictionary *data = [dict objectForKey:@"data"];
            NSLog(@"%@",request.responseString);
            GoodsDetailInfo *detail = [GoodsDetailInfo praseTheGoodsDetailInfo:data];
            block(detail);
        }
      
       
               
    }];
    [request startAsynchronous];
    
}
//+(void)requestInfoClassOfGoodsProducts
#pragma mark - gowuche (shoppingCar)
+(void)getGouWuCheList:(void(^)( ShoppingCar*car))block{
    
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/cart/list",HTTPS_ID]]];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    
    [request setCompletionBlock:^{
        NSLog(@"zzzz%@",request.responseString);
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
         int errcode = [dict[@"errcode"] intValue];
        if(errcode==10014||errcode==10100){
            block(nil);
        }else{
            ShoppingCar*car=[ShoppingCar praseWithDictionary:dict];
            block(car);
        };
         
    }];    
    [request startAsynchronous];
}
+(void)addGoodsToShouCangJiaItemID:(NSString *)itemID completion:(void(^)(NSString *errmsg))block{
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/cart/to-favorite",HTTPS_ID]]];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:itemID forKey:@"itemId"];
    [request setCompletionBlock:^{
        NSLog(@"llll it%@\n%@",itemID,request.responseString);
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSString *msg = dict[@"errmsg"];
        block(msg);
    }];
    [request startAsynchronous];
    
}
+(void)deleteCarWithGroups:(NSMutableArray *)groupsArr itemsArray:(NSMutableArray*)itemsArray completion:(void(^)(NSString *errmsg))block{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/cart/del",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    
    
    NSString *groups = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:groupsArr options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSLog(@"grasd  %@",groups);
  //  groups = [groups stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   
    NSString *items = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:itemsArray options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
     NSLog(@"item %@",items);
  //  items = [items stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    [request setPostValue:groups forKey:@"groups"];
    [request setPostValue:items forKey:@"items"];
    [request setCompletionBlock:^{
      
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        NSLog(@" msg %@\n%@",request.responseString,dict[@"errmsg"]);
        block(dict[@"errmsg"]);
    }];
     [request startAsynchronous];
    
}
+(void)addNumberItemID:(NSString *)itemID num:(NSString *)num completion:(void(^)(NSString *errmsg))block{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/cart/num",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:itemID forKey:@"itemId"];
    [request setPostValue:num forKey:@"num"];
    
    [request setCompletionBlock:^{
        NSLog( @"----%@",request.responseString);
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        //ok 添加成功  失败提示原因
        NSString *errmsg = dict[@"errmsg"];
        block(errmsg);
        
    }];
    
    [request startAsynchronous];
    
    
    
}



//获取手机验证码
+(void)requestGetShouJiYanZhengMa:(NSString*)phone compeletion:(void(^)(int errcode,NSString*errmsg))compeletion
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/comm/captcha_send",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:phone forKey:@"phone"];
    
    request.completionBlock=^
    {
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        
       
        if (compeletion)
        {
           // [self saveToken:token];
            compeletion(errcode,errmsg);
        }
    };
    [request startAsynchronous];
    

}


#pragma mark - 上架
+(void)requestGetShangJiaShangPinProducts:(NSMutableArray *)products  requestUrl:(NSString *)url Competion:(void(^)(int errcode,NSString*errmsg))Complete
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/shop/product_%@",HTTPS_ID,url]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    
    NSMutableArray *product = [NSMutableArray arrayWithArray:products];
    
    NSString *str =[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:product options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];

    [request setPostValue:str forKey:@"products"];
    request.completionBlock=^
    {
       NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];

        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
      
        if (Complete)
        {
            // [self saveToken:token];
            Complete(errcode,errmsg);
        }
    };
    [request startAsynchronous];
    
}

//个人集市
+(void)requestToGetGRJSCompletion:(void(^)(GeRenJiShi*gr))completion;
{
   
    NSString*str=[NSString stringWithFormat:@"%@/shop/personal_list",HTTPS_ID];
    //NSURL*url=[NSURL URLWithString:@"http://121.42.211.76/shop/mine_home?page=0&token=31447845156269"];
    NSURL*url=[NSURL URLWithString:str];
    __weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:@"0" forKey:@"page"];
    
    request.completionBlock=^
    {
        
        NSLog(@"zzzz%@",request.responseString);
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (completion)
            {
                completion(nil);
            }
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            
            GeRenJiShi*geRen=[GeRenJiShi userWithDictionary:dataDic];
            if (completion)
            {
               
                completion(geRen);
            }

        }
      
    };
    [request startAsynchronous];
    
}

#pragma mark - 删除购物车

+(void)deleteGoodsFromShoppingCarItems:(int)items groups:(int )groups completionBlock:(void(^) (NSString *errmsg))block{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/cart/del",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:[NSNumber numberWithInt:items] forKey:@"items"];
    [request setPostValue:[NSNumber numberWithInt:groups] forKey:@"groups"];
    
    [request setCompletionBlock:^{
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
        NSString *errmsg = [dict objectForKey:@"errmsg"];
        
        block(errmsg);
    }];
    [request startAsynchronous];
    
}

#pragma mark - 加入购物车
+(void)addGoodsInShoppingCarWithProductId:(int)shopProductId completionBlock:(void(^) (NSString *errmsg))block{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/cart/add",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:[NSNumber numberWithInt:shopProductId] forKey:@"shopProductId"];
    ;
 [request setCompletionBlock:^{
     
     NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
     NSString *errmsg = [dict objectForKey:@"errmsg"];
     
     block(errmsg);
     //ok 添加成功  失败提示原因
     
     
 }];

    [request startAsynchronous];
}

#pragma mark -银行列表
+(void)banklist:(void(^)(NSArray *bankArray))block{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/comm/bank_list",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];

    [request setCompletionBlock:^{
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingAllowFragments error:nil];
         int errcode = [dict[@"errcode"] intValue];
        BEGAIN_LOGIN_block(NSArray *data = dict[@"data"];
                           NSMutableArray *bankArray = [NSMutableArray array];
                           for (NSDictionary *list in data) {
                               BankList *bank = [BankList praseBankWithDiactionary:list];
                               [bankArray addObject:bank];
                           }
                           //ok 添加成功  失败提示原因
                           
                           block(bankArray);
)

            }];
    
    [request startAsynchronous];
    
    
    
}


//搜索结果页
+(void)requestSouSuoJieGuo:(NSString*)name tab:(NSString*)tab completion:(void(^)(SouSuoJieGuo*search))completion
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/product/search",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:@"true" forKey:@"brandDistri"];
    [request setPostValue:name forKey:@"name"];
    [request setPostValue:@"0" forKey:@"page"];
    [request setPostValue:tab forKey:@"tab"];
    request.completionBlock=^
    {
      
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (completion) {
                completion(nil);
            }
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            SouSuoJieGuo*search=[SouSuoJieGuo userWithDictionary:dataDic];
            if (completion)
            {
                completion(search);
            }
        }
  
  
        };
        
           [request startAsynchronous];
        
    
    
}

// 商品详情
+(void)requestToGetShangPinXiangQingCompletion:(NSString*)productId com:(void(^)(ShangPinXiangQing*shangPin))completion;
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/product/info",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:productId forKey:@"productId"];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    request.completionBlock=^
    {
        NSLog(@"aaaa%@",request.responseString);

        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (completion) {
                completion(nil);
            }
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            
            ShangPinXiangQing*sP=[ShangPinXiangQing userWithDictionary:dataDic];
            
            
            
            if (completion)
            {
                
                completion(sP);
            }

        }

            };
    [request startAsynchronous];
    
}

//加入购物车
+(void)requestToGetJiaRuGouWuCheCompletion:(jiaRuGouWuChe*)jiaRu completion:(void(^)(int error,NSString*errmsg))completion;
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/cart/add",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:jiaRu.productId forKey:@"productId"];
   [request setPostValue:jiaRu.shopId forKey:@"shopId"];
    
   
  
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:jiaRu.attr1Id forKey:@"attr1Id"];
    [request setPostValue:jiaRu.attr2Id forKey:@"attr2Id"];
    [request setPostValue:jiaRu.num forKey:@"num"];
    request.completionBlock=^
    {

        
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];

        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
    
        if (completion)
        {
            
            completion(errcode,errmsg);
        }
    };
    [request startAsynchronous];
}

//获取获取商品分类属性选择列表
+(void)requestToGetShangPinFenLeiShuXingProductID:(NSString *)productID Completion:(void(^)(NSArray*ary))completion
{
    
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/product/class_attr_list",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:productID forKey:@"productId"];
    
    request.completionBlock=^
    {
        NSLog(@"qqqqq%@",request.responseString);
       NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
 
        if ([jsonDic[@"data"] isKindOfClass:[NSNull class]]) {
            completion(nil);
        }else{
            NSMutableArray*dataAry=jsonDic[@"data"];
            NSMutableArray*resuleAry=[NSMutableArray array];
            
            if (dataAry.count>0) {
                for (int i=0; i<dataAry.count; i++)
                {
                    ShangPinFeNLeiShuXing*sP=[ShangPinFeNLeiShuXing userWithDictionary:dataAry[i]];
                    [resuleAry addObject:sP];
                }
                
                if (completion)
                {
                    
                    completion(resuleAry);
                }
                
            }else{
                completion(nil);
            }
        };
        
    };    [request startAsynchronous];
  
}

#pragma mark -zhifu 

//易宝支付
+(void)requestYiBaoZhiFu:(YiBaoZhiFu*)yiBao completion:(void(^)(int paycode,NSString*paymsg))Complete
{
    NSLog(@"易宝支付  %@%@%@%@",yiBao.paymentId,yiBao.shenFenZheng,yiBao.name,yiBao.phone);
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/payment/pay",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:yiBao.paymentId forKey:@"paymentId"];
    [request setPostValue:yiBao.shenFenZheng forKey:@"idCardCode"];
    
    [request setPostValue:yiBao.name forKey:@"buyerName"];
   
    [request setPostValue:yiBao.phone forKey:@"buyerTel"];
    [request setPostValue:yiBao.YinHangKa forKey:@"creditCardCode"];
    [request setPostValue:yiBao.youXiaoQiNian forKey:@"expireYear"];
    [request setPostValue:yiBao.youXiaoQiYue forKey:@"expireMonth"];
    [request setPostValue:yiBao.cvv forKey:@"cvv"];
    request.completionBlock=^
    {
       
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
      //  NSString*errmsg=jsonDic[@"errmsg"];
        NSDictionary*dataDic=jsonDic[@"data"];

        NSString*str=[NSString stringWithFormat:@"%d",errcode];
        if ([str isEqualToString:@"0"] )
        {
            int paycodez=[dataDic[@"paycode"]intValue];
            NSString*paymsgz=dataDic[@"paymsg"];
            if (Complete)
            {
                
                Complete(paycodez,paymsgz);
            }
      }
    };
    [request startAsynchronous];
    
}

//我的微电   最近几天上线
+(void)requestWDWD:(NSString*)shopID completion:(void(^)(WDWD*me))complete;
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/shop/product_home",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:shopID forKey:@"shopId"];
    [request setPostValue:@"0" forKey:@"page"];
    
    
    request.completionBlock=^
    {
    //http://121.42.211.76/user/login?phone=4&password=123456
        NSLog(@"zzzz%@",request.responseString);

        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==12700)
        {
            if (complete)
            {
                complete(nil);
            }
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            WDWD*me=[WDWD userWithDictionary:dataDic];
            if (complete)
            {
                complete(me);
            }
        }
       
       
    };
    [request startAsynchronous];
    
}

//收藏
+(void)requestGetshouCang:(NSString*)str shop:(NSString*)shopId  Competion:(void(^)(int errcode,NSString*errmsg))Complete;
{
    
    NSString*urlStr=[NSString stringWithFormat:@"%@/user/favorite_add",HTTPS_ID];
    NSURL*url=[NSURL URLWithString:urlStr];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:url];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:str forKey:@"productId"];
   //[request addPostValue:shopId forKey:@"shopId"];//商店
    NSLog(@"%@ +++ %@",str,shopId);
    request.completionBlock=^
    {
        
        NSLog(@"%@",request.responseString);
      NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        // NSDictionary*dataDic=jsonDic[@"data"];
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];

        if (Complete)
        {
            
            Complete(errcode,errmsg);
        }
        
    };
    [request startAsynchronous];
}
//更新店铺资料
+(void)regquestGengXin:(GengXinDianPuZiLiao*)gengXin completion:(void(^)(int errcode,NSString*errmsg))completion
{
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/shop/info_update",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
  
    NSScanner *scanner = [NSScanner scannerWithString:gengXin.closeminute];
    [scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
    int number;
    [scanner scanInt:&number];
   
    NSArray*ary=[gengXin.closeminute componentsSeparatedByString:@"时"];
    NSString*a=ary[1];
    NSScanner *b = [NSScanner scannerWithString:a];
    [b scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
    int fen;
    [scanner scanInt:&number];
    NSLog(@"%@%@%@%@",gengXin.name,gengXin.wechat,gengXin.phone,gengXin.closeminute);
    int c=number*3600+fen*60;
    NSString*time=[NSString stringWithFormat:@"%d",c];
   
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:gengXin.name forKey:@"name"];
    [request setPostValue:gengXin.wechat forKey:@"wechat"];
    [request setPostValue:gengXin.phone forKey:@"phone"];
    
    [request setPostValue:time forKey:@"closeminute"];
   
    
    request.completionBlock=^
    {
        NSLog(@"qqq%@",request.responseString);
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
       
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        if (completion)
        {
            completion(errcode,errmsg);
        }
        
        
        
        
    };
    [request startAsynchronous];
  
}
//取消订单
+(void)requestQuXiaoDingDanCompletion:(NSString*)orderId completion:(void(^)(NSString*errmsg,int errcode))complete
{
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/order/cancel",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:orderId forKey:@"orderId"];
    request.completionBlock=^
    {
        
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=[jsonDic[@"errmsg"]copy];
        if (complete) {
            complete(errmsg,errcode);
        }
        
        
        
        
        
    };
    [request startAsynchronous];
}
//评价
+(void)requestPingJiaCompletion:(NSString*)orderId pingFen:(NSString*)service coment:(NSString*)comment completion:(void(^)(int errcode,NSString*errmsg))completion
{
    
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/order/evaluate",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:orderId forKey:@"orderId"];
    [request setPostValue:service forKey:@"serviceScore"];
    [request setPostValue:comment forKey:@"comment"];
    request.completionBlock=^
    {
        
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=[jsonDic[@"errmsg"]copy];
        if (completion) {
            completion(errcode,errmsg);
        }
    };
    [request startAsynchronous];
}
//修改店铺招牌
+(void)requestDianPuZhaoPaiImage:(UIImage*)image completion:(void(^)(int errcode,NSString*errmsg))complete
{
    NSString*str=[NSString stringWithFormat:@"%@/shop/brand_mod",HTTPS_ID];
    NSURL*url=[NSURL URLWithString:str];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:url];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    
    
    NSData*data=UIImageJPEGRepresentation(image, 0.5);
    [request addData:data withFileName:@"testimage.png" andContentType:@"image/png" forKey:@"brand"];
  
    request.completionBlock=^
    {
               NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        if (complete)
        {
            complete(errcode,errmsg);
        }
        
        
    };
    [request startAsynchronous];
    
}

+(void)postimage:(UIImage *)img block:(void(^)(NSString *err))block{
    NSString*str=[NSString stringWithFormat:@"%@/user/avatar_mod",HTTPS_ID];
    NSURL*url=[NSURL URLWithString:str];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:url];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    
    
    NSData*data=UIImageJPEGRepresentation(img, 1);
    [request addData:data withFileName:@"filephoto.jpg" andContentType:@"image/jpeg" forKey:@"avatar"];
    //[request addFile:image forKey:@"brand"];
    [request appendPostData:data];
    
    request.completionBlock=^
    {
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        NSLog( @"img %@",request.responseString);
        block(errmsg);
        
    };
    [request startAsynchronous];
   
    
}
//020订单
+(void)requestGetWodeDingDan:(NSString*)str  Competion:(void(^)(woDeDingDan*dingDan))Complete
{
    
    NSString*zstr=[NSString stringWithFormat:@"%@/o2ocounter/order_list",HTTPS_ID];
    NSURL*url=[NSURL URLWithString:zstr];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:url];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:@"0" forKey:@"page"];
    [request addPostValue:str forKey:@"status"];
    NSLog(@"+++++++%@",str);
    request.completionBlock=^
    {
        NSLog(@"020收银订单%@",request.responseString);
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (Complete)
            {
                Complete(nil);
            }
            

        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            
            woDeDingDan*dD=[woDeDingDan userWithDictionary:dataDic];
            if (Complete)
            {
                Complete(dD);
            }
        }
        
    };
    [request startAsynchronous];
    
}

//微信订单
+(void)requestGetWeiDianDingDan:(NSString*)str type:(NSString*)type Competion:(void(^)(weiXinDingDan*weiDian))Complete
{
    NSLog(@"++++++++%@",str);
    NSString*strz=[NSString stringWithFormat:@"%@/order/list",HTTPS_ID];
    NSURL*url=[NSURL URLWithString:strz];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:url];
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:@"0" forKey:@"page"];
    [request addPostValue:str forKey:@"status"];
    [request addPostValue:@"3" forKey:@"type"];
    request.completionBlock=^
    {
        NSLog(@"zzz%@",request.responseString);
       
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==ERRCODE_WUXIAO||errcode==ERRCODE_BCZ)
        {
            if (Complete)
            {
                
                Complete(nil);
            }
        }
        else
        {
            
            NSDictionary*dataDic=jsonDic[@"data"];
            
            
            
            weiXinDingDan*weiXin=[weiXinDingDan userWithDictionary:dataDic];
            
            
            if (Complete)
            {
                
                Complete(weiXin);
            }
            
        }
        
        
    };
    [request startAsynchronous];
    
}
//请求生成支付
+(void)requestGet020ShouYinTai:(o2oShouYinTai*)shouYin   Competion:(void(^)(ZhiFuDiaoYongJIeKou*zhiFu))Complete
{
    NSString*strz=[NSString stringWithFormat:@"%@/payment/request",HTTPS_ID];
    NSURL*url=[NSURL URLWithString:strz];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:url];
    
    [request addPostValue:ACCESS_TOKEN forKey:@"token"];
    [request addPostValue:shouYin.totalCharge forKey:@"totalCharge"];
    [request addPostValue:shouYin.paymentType forKey:@"paymentType"];
    [request addPostValue:shouYin.o2o forKey:@"o2o"];
    if ([shouYin.o2o isEqualToString:@"false"])
    {
        [request addPostValue:shouYin.orderIdStr forKey:@"orderIds"];
    }
  
    request.completionBlock=^
    {
   
       // __strong typeof(request) strongRequest = request;
        NSLog(@"aaaaa%@",request.responseString);
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (Complete) {
                Complete(nil);
            }
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            ZhiFuDiaoYongJIeKou*zhiFu=[ZhiFuDiaoYongJIeKou userWithDictionary:dataDic];
            
            
            if (Complete)
            {
                
                Complete(zhiFu);
            }

        }
        
    };
    [request startAsynchronous];

}

//获取支付短信验证码
+(void)requestGetZhiFuYanZhengMa:(duanXinYanZheng*)duanXin completion:(void(^)(int errcode,NSString*errmsg))Complete
{
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/payment/verify-send",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:duanXin.paymentId forKey:@"paymentId"];
    //[request setPostValue:duanXin.captcha forKey:@"captcha"];
    
    
    request.completionBlock=^
    {
        

        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        
        if (Complete)
        {
            Complete(errcode,errmsg);
        }
        
        
        
    };
    [request startAsynchronous];
    
    
    
    
}
//易宝支付短信验证
+(void)registerDuanXinYanZheng:(duanXinYanZheng*)duanXin completion:(void(^)(int paycode,NSString*paymsg))completion
{
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/payment/verify-pay",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:duanXin.paymentId forKey:@"paymentId"];
    [request setPostValue:duanXin.captcha forKey:@"captcha"];
    
    
    request.completionBlock=^
    {
       
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        //int errcode=[jsonDic[@"errcode"]intValue];
       // NSString*errmsg=jsonDic[@"errmsg"];
        
        NSDictionary*dataDic=jsonDic[@"data"];
        
       // NSString*str=[NSString stringWithFormat:@"%d",errcode];
        //if ([str isEqualToString:@"0"])
       // {
            int paycodez=[dataDic[@"paycode"]intValue];
            NSString*paymsgz=dataDic[@"paymsg"];
            if (completion)
            {
                
                completion(paycodez,paymsgz);
            }
            
            
      //  }
        
        
        
    };
    [request startAsynchronous];

    
}

//我的商品
+(void)registerWoDeShangPin:(NSString*)shopId type:(NSString*)type completion:(void(^)(int errcode, ShangPinGuanLi*guanLi))completion
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/shop/product_filter",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:shopId forKey:@"shopId"];
    [request setPostValue:@"0" forKey:@"page"];
    [request setPostValue:type forKey:@"type"];
    
    request.completionBlock=^
    {
        NSLog(@"....0000111111%@",request.responseString);
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        //int errcode=[jsonDic[@"errcode"]intValue];
        // NSString*errmsg=jsonDic[@"errmsg"];
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==ERRCODE_WUXIAO||errcode==ERRCODE_BCZ||errcode==ERRCODE_SHOPNOT)
        {
            if (completion) {
                completion(errcode,nil);
            }
        }
        
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            
            ShangPinGuanLi*shangPin=[ShangPinGuanLi userWithDictionary:dataDic];
            if (completion)
            {
                completion(errcode,shangPin);
            }
        }
        
        
        
        
    };
    [request startAsynchronous];
    
}
//置顶接口
+(void)registerzhiDing:(NSString*)productId  completion:(void(^)(NSString*errmsg))completion
{
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/shop/product-top",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:productId forKey:@"productId"];
   
    
    request.completionBlock=^
    {
       
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
      
        //int errcode=[jsonDic[@"errcode"]intValue];
         NSString*errmsg=jsonDic[@"errmsg"];
        
        
        
        
        if (completion)
        {
            completion(errmsg);
        }
        
        
        
    };
    [request startAsynchronous];

    
    
    
    
}
//立即下单
+(void)requestLiJiXiaDan:(JiaRuModel*)model  completion:(void(^)(NSString*orderId,NSString*money,NSString*errmsg,int errcode))completion
{
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/order/create",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    NSLog(@"aa%@ aa%@  aa%@  aa%@  aa%@",model.productId,model.shopId,model.attr1Id,model.attr2Id,model.num);
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:model.productId forKey:@"productId"];
     [request setPostValue:model.shopId forKey:@"shopId"];
     [request setPostValue:model.attr1Id forKey:@"attr1Id"];
     [request setPostValue:model.attr2Id forKey:@"attr2Id"];
     [request setPostValue:model.num forKey:@"num"];
     [request setPostValue:model.addresseeId forKey:@"addresseeId"];
    
    request.completionBlock=^
    {
        NSLog(@"aa%@",request.responseString);
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        
        if (errcode==0)
        {
            NSDictionary*dataDic=jsonDic[@"data"];
           int orderId=[dataDic[@"orderId"]intValue];
            NSString*strOrderId=[NSString stringWithFormat:@"%d",orderId];
            int money=[dataDic[@"money"]intValue];
           
            NSString*moneyStr=[NSString stringWithFormat:@"%.2f",money*0.01];
            
            if (completion)
            {
                completion(strOrderId,moneyStr,errmsg,errcode);
            }
                    }
        
       // NSString*errmsg=jsonDic[@"errmsg"];
        
        
        else
        {
            NSString*orderId=@"";
            NSString*money=@"";
            
            NSLog(@"zzz%@",errmsg);
            completion(orderId,money,errmsg,errcode);
        }

        
        
        
        
        
    };
    [request startAsynchronous];

}
//店铺资料

+(void)requestGetDianPuSheZhi:(void(^)(NSMutableArray*xinXiAry))Complete
{
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@shop/personal_shop",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    
    request.completionBlock=^
    {
       
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",request.responseString);
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (Complete) {
                Complete(nil);
            }
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
             NSMutableArray*xXAry=[NSMutableArray array];
            HuoQuDianPuSheZhi*huo=[HuoQuDianPuSheZhi userWithDictionary:dataDic];
            [xXAry addObject:huo];
            if (Complete)
            {
                Complete(xXAry);
            }

        }
    };
    [request startAsynchronous];

    
    
    
    
    
    
    
    
    
    
}
//品牌分校
+(void)requestPinPaiFenXiao:(NSString*)brandDistri categoryID:(NSString *)categoryID sub:(NSString*)sub  page:(NSString *)page shopID:(NSString *)shopID  tab:(NSString *)tab completion:(void(^)(PinPaiFenXiao*pinPai))complete

{
    /*page=0        // 分页
     brandDistri=1 // 可选,表示品牌商品
     categoryId＝1 // 可选（空表示全部）
     subcategoryId＝1 // 可选（空表示全部）
     shopId=12 // 可选（空表示不限制）
     */
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@product/list",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    
    [request setPostValue:brandDistri forKey:@"brandDistri"];
    [request setPostValue:categoryID forKey:@"categoryId"];
    [request setPostValue:sub forKey:@"subcategoryId"];
    [request setPostValue:page forKey:@"page"];
    [request setPostValue:shopID forKey:@"shopId"];
    [request setPostValue:tab forKey:@"tab"];
    request.completionBlock=^
    {
        
        NSLog(@"---------%@",request.responseString);
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode == 10100||errcode ==10014) {
            complete(nil);
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            PinPaiFenXiao*pinP=[PinPaiFenXiao userWithDictionary:dataDic];
            if (complete)
            {
                complete(pinP);
            }
        }
        
        
    };
    [request startAsynchronous];
    
}

//账单明细
+(void)requestZhangDanMingXi:(NSString*)type  completion:(void(^)(ZhangDanMingXi*mingXi))complete{
    
    
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/profit/billing_details",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:type forKey:@"type"];
    [request setPostValue:@"0" forKey:@"page"];
    request.completionBlock=^
    {
        NSLog(@"aaaaa%@",request.responseString);
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
   
        int errcode=[jsonDic[@"errcode"]intValue];
        
        if (errcode==10014||errcode==10100)
        {
            if (complete)
            {
                complete(nil);
            }
            
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            ZhangDanMingXi*pinP=[ZhangDanMingXi userWithDictionary:dataDic];
            if (complete)
            {
                complete(pinP);
            }
        }
   
    };
    [request startAsynchronous];

    
    
    
}

//分润累计收入
+(void)requestFenRunLeiJiShouRu:(NSString*)type comoletion:(void(^)(FebRunLeiJiShouRu*fenRun))complete
{
    
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/profit/contribute_list",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:type forKey:@"type"];
    [request setPostValue:@"0" forKey:@"page"];
    request.completionBlock=^
    {
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (complete) {
                complete(nil);
            }
        }
        
            else
            {
                NSDictionary*dataDic=jsonDic[@"data"];
                FebRunLeiJiShouRu*fenRun=[FebRunLeiJiShouRu userWithDictionary:dataDic];
                if (complete)
                {
                    complete(fenRun);
                }
            }
        
        
 
        
    };
    [request startAsynchronous];

    
}
//  结算页面数据
+(void)requestJieSuan:(NSString*)accountId comoletion:(void(^)(JieSuanShuJu*jieSuan))complete
{
    
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/profit/settle-info",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:accountId forKey:@"accountId"];
   
    request.completionBlock=^
    {
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
        if (errcode==10014||errcode==10100)
        {
            if (complete) {
                complete(nil);
            }
        }
        else
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            JieSuanShuJu*fenRun=[JieSuanShuJu userWithDictionary:dataDic];
            if (complete)
            {
                complete(fenRun);
            }
        }
 
    };
    [request startAsynchronous];

}
//结算

+(void)requestJieSuanAnNiu:(NSString*)accountId amont:(NSString*)amount comoletion:(void(^)(NSString*errmsg,int errcode, NSString* walletId,NSString* amount))complete
{
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/profit/settle",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    [request setPostValue:accountId forKey:@"accountId"];
    [request setPostValue:amount forKey:@"amount"];
    request.completionBlock=^
    {
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
    
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        
        if (errcode==0)
        {
            NSDictionary*dataDic=jsonDic[@"data"];
            int walletId=[dataDic[@"walletId"]intValue];
            NSString*str1=[NSString stringWithFormat:@"%d",walletId];
            int amount=[dataDic[@"amount"]intValue];
            NSString*str2=[NSString stringWithFormat:@"%d",amount];
            if (complete)
            {
                complete(errmsg,errcode,str1,str2);
            }
            
            
        }
        else
        {
            if (complete)
            {
                complete(errmsg,errcode,nil,nil);
            }
        }
   
        
    };
    [request startAsynchronous];
 
}

//微店累计收入
+(void)requestWeiDianLeiJiShouRuCompletion:(void(^)(NSMutableArray*shouRuAry))completion
{
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/shop/income-detail",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    request.completionBlock=^
    {
        NSLog(@"....ccccc%@",request.responseString);
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        
        if (errcode==10014||errcode==10100)
        {
            if (completion)
            {
                completion(nil);
            }
            
            
        }
        else
        {
            NSMutableArray*dataAry=jsonDic[@"data"];
            NSMutableArray*resultAry=[NSMutableArray array];
            if (dataAry.count>0)
            {
                for (int i=0; i<dataAry.count; i++)
                {
                    WeiDianLeiJiShouRu*weiDian=[WeiDianLeiJiShouRu userWithDictionary:dataAry[i]];
                    [resultAry addObject:weiDian];
                }
                if (completion)
                {
                    completion(resultAry);
                }
            }
            
            
            
            
        }
        
        
        
        
        
        
        
        
    };
    [request startAsynchronous];
    
    
    
    
    
}
//确认订单
+(void)requestqueRenXiaDan:(NSMutableArray*)itmes address:(NSString*)addresseeId  completion:(void(^)(NSMutableArray*ordersAry,int totalMoney,NSString*errmsg,int errcode))completion {
    NSLog(@"ggg%@",itmes);
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/cart/submit",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
    [request setPostValue:ACCESS_TOKEN forKey:@"token"];
    
    NSString *arr = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:itmes options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    [request setPostValue:arr forKey:@"items"];
    [request setPostValue:addresseeId forKey:@"addresseeId"];
    request.completionBlock=^
    {
        NSLog(@"....ccccc%@",request.responseString);
        
        //http://121.42.211.76/user/login?phone=4&password=123456
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
       
        int errcode=[jsonDic[@"errcode"]intValue];
        NSString*errmsg=jsonDic[@"errmsg"];
        if (![jsonDic[@"data"]isKindOfClass:[NSNull class] ])
        {
              NSDictionary*dataDic=jsonDic[@"data"];
            NSMutableArray*orderAry=dataDic[@"orders"];
            int totalMoney=[dataDic[@"totalMoney"]intValue];
            NSMutableArray*orderwsAry=[NSMutableArray array];
            for (int i=0; i<orderAry.count; i++)
            {
                QueRenDingDan*queRen=[QueRenDingDan userWithDictionary:orderAry[i]];
                [orderwsAry addObject:queRen];
                
            }
            if (completion)
            {
                completion(orderwsAry,totalMoney,errmsg,errcode);
            }
            
        }
      

        
        
        
        
        
        
        
        
    };
    [request startAsynchronous];

    
    
    
}
//值得搜
+(void)requestZhiDeSouCompletion:(void(^)(NSMutableArray*zhiDeAry))completion
{
    
    NSURL*URL=[NSURL URLWithString:[NSString stringWithFormat:@"%@product/hot_search",HTTPS_ID]];
    __weak ASIFormDataRequest*request=[ASIFormDataRequest requestWithURL:URL];
   
    request.completionBlock=^
    {
       
        NSDictionary*jsonDic=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"search ????%@",jsonDic);
        
       if (![jsonDic[@"data"]isKindOfClass:[NSNull class]])
        {
            NSMutableArray*dataAry=jsonDic[@"data"];
            NSMutableArray*resuleAry=[NSMutableArray array];
            if (dataAry.count>0)
            {
                for (int i=0; i<dataAry.count;i++)
                {
                    ZhiDeSou*zhiDe=[ZhiDeSou userWithDictionary:dataAry[i]];
                    [resuleAry addObject:zhiDe];
                    
                }
                if (completion) {
                    completion(resuleAry);
                }
                
                
                
            }
            
        }
        
        
        
        
        
        
        
        
        
        
    };
    [request startAsynchronous];
    
    
    
    
    
    
    
    
    
    
}


@end
